package com.bole.controller;

import com.bole.data.Result;
import com.bole.data.ResultEnum;
import com.bole.dto.content.DicContentTypeDto;
import com.bole.dto.img.DicImgTypeDto;
import com.bole.feign.DicImgTypeFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("imgtype")
@Api(value = "图片类型管理接口")
public class ImgTypeController {
    @Autowired
    private DicImgTypeFeign dicImgTypeFeign;


    @RequestMapping("tolist")
    public String toList(){

        return "img-type-list";
    }



    @GetMapping("getImgTypeInfo")
    @ApiOperation(value = "查询图片类型")
    @ResponseBody
    public Result getImgTypeInfo(){
        List<DicImgTypeDto> list =  dicImgTypeFeign.getImgTypeInfo();
        return Result.response(ResultEnum.OK).setData(list);
    }


    @PostMapping("saveImgTypeInfo")
    @ApiOperation(value = "增加类型信息")
    @ApiImplicitParam(name = "dicImgTypeDto",value = "类型对象",required = true,dataTypeClass = DicImgTypeDto.class)
    @ResponseBody
    public Result saveImgTypeInfo(@RequestBody DicImgTypeDto dicImgTypeDto){
        dicImgTypeFeign.saveImgTypeInfo(dicImgTypeDto);
        return Result.response(ResultEnum.OK);
    }


    @PostMapping("toUpdate/{id}")
    @ApiOperation(value = "回显")
    @ApiImplicitParam(name = "id",value = "类型id",required = true,dataTypeClass = Integer.class)
    @ResponseBody
    public Result toUpdate(@PathVariable("id")Integer id){
        DicImgTypeDto dicImgTypeDto = dicImgTypeFeign.toUpdate(id);
        return Result.response(ResultEnum.OK).setData(dicImgTypeDto);
    }


    @PostMapping("updateImgTypeInfo")
    @ApiOperation(value = "修改信息")
    @ApiImplicitParam(name = "dicImgTypeDto",value = "类型对象",required = true,dataTypeClass = DicImgTypeDto.class)
    @ResponseBody
    public Result updateContentCateInfo(@RequestBody DicImgTypeDto dicImgTypeDto){
        dicImgTypeFeign.updateImgTypeInfo(dicImgTypeDto);
        return Result.response(ResultEnum.OK);
    }


    @PostMapping("deleteBatch/{ids}")
    @ApiOperation(value = "批量删除信息")
    @ApiImplicitParam(name = "ids",value = "类型id",required = true,paramType = "path",dataTypeClass = Integer.class)
    @ResponseBody
    public Result deleteBatch(@PathVariable("ids")Integer[] ids){
        List<Integer> idss = new ArrayList<>();
        for (Integer id : ids) {
            idss.add(id);
        }
        dicImgTypeFeign.deleteBatch(idss);
        return Result.response(ResultEnum.OK);
    }


}
